﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using WiMo.Games.WM5.Drawables;
using System.Drawing;

namespace WiMo.Games.WM5
{
    internal class GameForm : Form
    {
        public event EventHandler GameFormResize;
        public event EventHandler Continue;

        private string _status = string.Empty;

        public GameForm()
        {
            InitializeComponent();
            this.Deactivate += new EventHandler(GameForm_Deactivate);
        }

        void GameForm_Deactivate(object sender, EventArgs e)
        {
            if (GameFormResize != null)
                GameFormResize(this, null);
        }

        protected override void OnResize(EventArgs e)
        {
            if (GameFormResize != null)
                GameFormResize(this, null);

            base.OnResize(e);
        }

        

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            if (FormEnabled)
                GradientFill.Fill(e.Graphics, Bounds, System.Drawing.Color.LightBlue, System.Drawing.Color.White, GradientFill.FillDirection.TopToBottom);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            var font = new Font("Tahoma", 12f, FontStyle.Bold);
            var brush = new SolidBrush(System.Drawing.Color.Black);
            var white = new SolidBrush(System.Drawing.Color.White);
            var size = e.Graphics.MeasureString(_status, font);

            var offset = (e.Graphics.DpiX / 96);

            e.Graphics.DrawString(_status, font, white, ((Width - size.Width) / 2) + 1, 31);
            e.Graphics.DrawString(_status, font, brush, (Width - size.Width) / 2, 30);

            font.Dispose();;
        }

        private void InitializeComponent()
        {
            this.Text = "WiMo-GF Game";

            FormEnabled = false;
        }

        private void btnRestart_Click(object sender, EventArgs e)
        {
            if(Continue != null)
                Continue(this, null);
        }

        public bool FormEnabled
        {
            get;
            set;
        }

        public void SetStatus(string status)
        {
            _status = status;
        }
    }
}
